<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
        // 通过中间构造函数解决继承会修改父对象属性的问题

        
        function Teacher() {
            this.name = "张三";
            this.age = 28;
        }
        Teacher.prototype = {
            pSkill:'JS/JQ'
        }
        let t = new Teacher();
        console.log(t);

        // 圣杯模式

        function Buffer(){}
        Buffer.prototype = Teacher.prototype; 
        function Student(){
            this.name = "王武";
        }
        let buffer = new Buffer(); // 实例化的buffer对象有Teacher原型
        Student.prototype = buffer;  // Student的原型等于实例化buffer对象
        Student.prototype.aaa = "admin"; // 增加Studen对象属性 不会影响Teacher原型
        let s = new Student();
        console.log(s);

    </script>
</body>
</html>